package wn.tcpip.mq.consumer.config.stateQuery;

import com.alibaba.fastjson.JSONObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component("stateConsumerListener")
public class StateConsumerListener {
	Logger log = LogManager.getLogger(getClass());
	@Resource
	private JdbcTemplate jdbcTemplate;
	public void handleMessage(String message) {
		JSONObject jsonObject = JSONObject.parseObject(message);
		String sql ="update wn_dwsb set sbzt=? where imei =?";
		//dwsbId
		Object[] params = {jsonObject.getDouble("state").intValue(),jsonObject.getString("imei")};
		jdbcTemplate.update(sql,params);
		log.info("设备：{}，状态: {}", jsonObject.getString("imei"),jsonObject.getDouble("state").intValue());
	}

}